#ifndef WXSPROPERTYCONTAINER_H
#define WXSPROPERTYCONTAINER_H

#include "wxsproperty.h"
#include "wxsquickpropspanel.h"

#include <prep.h>

class wxsPropertyGridManager;


class wxsPropertyContainer {
  public:


    wxsPropertyContainer();


    virtual ~wxsPropertyContainer();


    void ShowInPropertyGrid();


    void XmlRead( TiXmlElement* Element );


    void XmlWrite( TiXmlElement* Element );


    void PropStreamRead( wxsPropertyStream* Stream );


    void PropStreamWrite( wxsPropertyStream* Stream );


    wxsQuickPropsPanel* BuildQuickPropertiesPanel( wxWindow* Parent );


    void NotifyPropertyChange( bool CallPropertyChangeHandler = false );


    inline wxsPropertyStream& operator>>( wxsPropertyStream& Stream ) {
      PropStreamRead( &Stream );
      return Stream;
    }


    inline wxsPropertyStream& operator<<( wxsPropertyStream& Stream ) {
      PropStreamWrite( &Stream );
      return Stream;
    }


    inline long GetPropertiesFlags() { return OnGetPropertiesFlags(); }

  protected:


    virtual long OnGetPropertiesFlags() { return -1; }


    virtual void OnEnumProperties( long Flags ) = 0;


    void Property( wxsProperty& Prop );


    inline void SubContainer( wxsPropertyContainer* Container ) {
      if( Container ) {
        SubContainer( Container, Container->GetPropertiesFlags() );
      }
    }


    inline void SubContainer( wxsPropertyContainer& Container ) {
      SubContainer( &Container );
    }


    void SubContainer( wxsPropertyContainer* Container, long NewFlags );


    inline void SubContainer( wxsPropertyContainer& Container, long NewFlags ) {
      SubContainer( &Container, NewFlags );
    }


    virtual wxsQuickPropsPanel* OnCreateQuickProperties( M_Code_unused wxWindow* Parent ) { return 0; }


    virtual void OnPropertyChanged() {}


    virtual void OnSubPropertyChanged( M_Code_unused wxsPropertyContainer* sc ) {}


    static const long flPropGrid   = 0x40000000;


    static const long flXml        = 0x20000000;


    static const long flPropStream = 0x10000000;


    virtual void OnAddExtraProperties( M_Code_unused wxsPropertyGridManager* Grid ) {}


    virtual void OnExtraPropertyChanged( M_Code_unused wxsPropertyGridManager* Grid,
                                         M_Code_unused wxPGId                  Id ) {}

  private:


    void NotifyPropertyChangeFromPropertyGrid();


    void NotifyPropertyChangeFromQuickProps();

    wxsQuickPropsPanel* CurrentQP;
    bool BlockChangeCallback;


    static long Flags;
    static bool IsRead;
    static TiXmlElement* CurrentElement;
    static wxsPropertyStream* CurrentStream;
    static wxMutex Mutex;
    friend class wxsPropertyGridManager;
    friend class wxsQuickPropsPanel;
    friend class wxsProperty;
};

#endif


